package com.ll.datedemo;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @author 刘龙
 * @version 1.0
 */
public class LocalDate01 {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        // 2021-03-24T11:34:29.346022400
        System.out.println(now);

        // 2021
        System.out.println(now.getYear());
        // 月 MARCH
        System.out.println(now.getMonth());
        // 月 3
        System.out.println(now.getMonthValue());
        // 日 23
        System.out.println(now.getDayOfMonth());
        // 时 11
        System.out.println(now.getHour());
        // 分 34
        System.out.println(now.getMinute());
        // 秒 29
        System.out.println(now.getSecond());

        // 获取日期
        LocalDate now1 = LocalDate.now();
        // 获取时间
        LocalTime now2 = LocalTime.now();

        // 日期时间格式化
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(now);
        // 2021-03-24 11:38:23
        System.out.println(format);

        // plus 和 minus 对当前时间进行加和减
        // 1000天后
        String format1 = now.plusDays(1000).format(dateTimeFormatter);
        // 2023-12-19 12:05:30
        System.out.println(format1);

        // 1000分钟前
        String format2 = now.minusMinutes(1000).format(dateTimeFormatter);
        // 2021-03-23 19:26:29
        System.out.println(format2);
    }
}
